/**
 * Demo script for AI Classification Service
 * This script demonstrates how to use the AI classification API
 */

const axios = require('axios');

// Server URL
const BASE_URL = 'http://localhost:3003';

// Demo function to test AI classification service
async function demoAIClassification() {
  try {
    console.log('=== AI Classification Service Demo ===\n');
    
    // In a real application, you would first authenticate the user
    console.log('1. User authentication would be required for all AI service requests');
    console.log('   (Authentication tokens would be included in request headers)\n');
    
    // Simulate a bill ID (in a real app, this would be an actual bill)
    const billId = 123;
    
    console.log(`2. Example bill: "在星巴克买咖啡" with amount -35.00`);
    console.log(`   Bill ID: ${billId}\n`);
    
    // Show the API endpoints
    console.log('3. AI Classification Service API Endpoints:');
    console.log(`   POST ${BASE_URL}/api/ai/bills/${billId}/suggest  - Generate AI suggestion`);
    console.log(`   POST ${BASE_URL}/api/ai/bills/${billId}/apply    - Apply AI suggestion`);
    console.log(`   GET  ${BASE_URL}/api/ai/bills/${billId}/suggestions - Get suggestion history\n`);
    
    // Simulate AI suggestion result
    console.log('4. Simulated AI Suggestion Result:');
    console.log('   {');
    console.log('     "message": "AI分类建议生成成功",');
    console.log('     "suggestion": {');
    console.log('       "suggested_category": "餐饮",');
    console.log('       "confidence": "high",');
    console.log('       "explanation": "基于账单标题\\"在星巴克买咖啡\\"和金额-35.00，系统建议分类为餐饮。"');
    console.log('     }');
    console.log('   }\n');
    
    // Explain the AI algorithm
    console.log('5. AI Algorithm Explanation:');
    console.log('   - Uses keyword matching to identify potential categories');
    console.log('   - Considers bill amount (positive for income, negative for expenses)');
    console.log('   - Assigns confidence levels based on match strength');
    console.log('   - Can be extended with machine learning models in the future\n');
    
    // Show benefits
    console.log('6. Benefits of AI Classification:');
    console.log('   - Reduces manual work for users');
    console.log('   - Improves categorization accuracy over time');
    console.log('   - Learns from user corrections');
    console.log('   - Provides explanations for transparency\n');
    
    console.log('=== Demo Complete ===');
    console.log('The AI classification service is ready for integration with the frontend.');
    
  } catch (error) {
    console.error('Error in demo:', error.message);
  }
}

// Run the demo
demoAIClassification();